﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace App.Validate
{
    public class GreaterThanValidator : Validator
    {
        public IComparable LowerBound { get; private set; }

        public GreaterThanValidator(string messageTemplate, IComparable lowerBound):base(messageTemplate)
        {
            Guard.ArgumentNotNull(lowerBound, "lowerBound");
            this.LowerBound = lowerBound;
        }

        public override ValidationError Validate(object objectToValidate)
        {
            if (this.LowerBound.CompareTo(objectToValidate) == -1)
            {
                return null;
            }
            else
            {
                return this.CreateValidationError(objectToValidate);
            }
        }

        public override void FormatMessage(object objectToValidate)
        {
            base.FormatMessage(objectToValidate);
            this.MessageTemplate = this.MessageTemplate.Replace("{LowerBound}", this.LowerBound.ToString());
        }
    }
}
